﻿#ifndef PLUGOBJECT_H
#define PLUGOBJECT_H
#include <QGraphicsItem>
#include <QGraphicsTextItem>
#include <QString>

class PlugObject : public QGraphicsItem
{
public:
    enum {Type = UserType + 2};
    explicit PlugObject(QGraphicsItem *parent, QGraphicsTextItem * carNumberItem ,QString *carIP);
    ~PlugObject();

    int type() const override { return Type; }


    //提供对外接口，实现对值的修改
    void PlugID(const QString &PlugID) {PlugName = PlugID;}
    void plugNumber(const QString &PlugNumber) { mPlugNumber = PlugNumber;}

    //这里调用就不会改变里面的变量，采用const是为了实现对值的不改变
    QString getcarNumber() const {return  carNumberItem->toPlainText(); }
    QString getPlugName() const {return  PlugName;}
    QString getPlugNumber() const {return  mPlugNumber;}
    QString getcarIP() const {return *carIP; }
    bool getIsATOrigin() const {return isAtOringin;}
    bool getIsMoving() const {return  isMoving;}
    bool getIsConnected() const{return  isConnected;}

    //实现对颜色的改变
    void mPCtoC0(){ myplugcolor = Color_0;}//原点位，未自检
    void mPCtoC1(){ myplugcolor = Color_1 ; isAtOringin = true; isMoving = false ; isConnected = false;}//原点位，自检正常
    void mPCtoC2(){myplugcolor = Color_2  ; isAtOringin = false; isMoving = true ; isConnected = false;} //动作中
    void mPCtoC3(){ myplugcolor = Color_3 ; isAtOringin = false; isMoving = false ; isConnected = true;}//伸出到位
   




protected:
    QRectF boundingRect() const override;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;

private:
    QGraphicsTextItem *carNumberItem;
    QString PlugName;
    QColor myplugcolor;
    QColor Color_0;
    QColor Color_1;
    QColor Color_2;
    QColor Color_3;
    QString mPlugNumber;
    QString *carIP;


    bool isAtOringin;
    bool isMoving;
    bool isConnected;


};


#endif // PLUGOBJECT_H
